/**
 * This class is a listener for fuel button
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class FuelListener implements ActionListener {
	
	/**
	 * Field ERSHI.
	 * (value is 20)
	 */
	private static final int ERSHI = 20;
	
	/**
	 * Field SHI.
	 * (value is 10)
	 */
	private static final int SHI = 10;
	
	/**
	 * Field WU.
	 * (value is 5)
	 */
	private static final int WU = 5;
	
	/**
	 * Field money.
	 */
	/**
	 * Field currentFuel.
	 */
	private final JLabel currentFuel, money;
	
	/**
	 * Constructor for FuelListener.
	 * @param currentFuel JLabel
	 * @param money JLabel
	 */
	public FuelListener(JLabel currentFuel, JLabel money) {
		this.currentFuel=currentFuel;
		this.money=money;
	}

	/**
	 * Method actionPerformed.
	 * @param arg0 ActionEvent
	
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		int cost;
		//if pilot skill point is higher than 10, player gets discount for fuel
		if (GameInfo.getPilotSP() >= WU) {
			cost = PlayerInfo.getMoney() -
					SHI * (PlayerInfo.FuelCapacity - PlayerInfo.getFuel()) *
					(ERSHI - GameInfo.getPilotSP()) / ERSHI;
		}else {
			cost = PlayerInfo.getMoney() -
					SHI * (PlayerInfo.FuelCapacity - PlayerInfo.getFuel());
		}
		if (cost < 0) {
			JOptionPane.showMessageDialog(
				ConfigurationScreen.MyFrame, "No enough money to add fuel");
			return;
		}
		PlayerInfo.setMoney(cost);
		this.money.setText(Integer.toString(PlayerInfo.getMoney()));
		PlayerInfo.setFuel(PlayerInfo.FuelCapacity);
		this.currentFuel.setText(Integer.toString(PlayerInfo.getFuel()));
	}
	
	/**
	 * Method toString.
	
	 * @return String */
	@Override
	public String toString() {
		return "FuelListener [currentFuel=" + currentFuel + ", money=" + money
				+ "]";
	}
}

